package com.hikeen.launcherx.utils;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;

public class ShowBigPhoto {
    private Context context;
    private String path;



    public ShowBigPhoto(Context context, String path){
        this.context = context;
        this.path = path;
    }

    public void showDetailPhoto(){
// 全屏显示的方法
        final Dialog dialog = new Dialog(context, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
        ImageView imgView = getView();
        dialog.setContentView(imgView);
        dialog.show();

// 大图显示之后，点击图片消失
        imgView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
    }

    //设置当前imgView的图片
    private ImageView getView() {
        ImageView imgView = new ImageView(context);
        imgView.setLayoutParams(new WindowManager.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT));
        imgView.setImageBitmap(decodeBigPhoto());
        return imgView;
    }

    private Bitmap decodeBigPhoto(){
        if (path != null) {
            Bitmap bigBitmap;
            BitmapFactory.Options opt = new BitmapFactory.Options();
            bigBitmap = BitmapFactory.decodeFile(path);
            opt.inSampleSize = 1;
            opt.inJustDecodeBounds = false;

            bigBitmap = BitmapFactory.decodeFile(path, opt);
//iv_photo.setImageBitmap(bigBitmap);
            return bigBitmap;
// releaseBitmap();
        }
        return null;

    }
}